var REPORT_PATH_PREFIX = "";

var TODO_PATH = "";

function setRegulatoryReportPath(path){
	REPORT_PATH_PREFIX =  path;
}

function setPathPreTodo(path){
	TODO_PATH = path;
}

$(function() {
	$('#reportType').select2({
		placeholder : "报告类型"
	});
	WASP_WIDGET.triggerDateRangeStyle("reportDate");
	WASP_WIDGET.triggerPrdInfoSelect("prdCode");
	WASP_WIDGET.triggerICheck();
	initICheck();
});

function initICheck(){
}

function judgeHasAttach(instIds,reprotDateBgn,reprotDateEnd){
	var resultData;
	$.ajax({
		dataType: "json",
		type:'GET',
		url:encodeURI(REPORT_PATH_PREFIX+"/checkRegulatoryReportAtt.do?sp[instIds]="+instIds+"&sp[reprotDateBgn]="+reprotDateBgn+"&sp[reprotDateEnd]="+reprotDateEnd+"&r="+Math.random()),
		async:false,
		success: function(data){
			resultData = data;
		},
	});
	return resultData;
}

function down(){
	var instIds = "";
	$.each($("input[name='instId']:checked"),function(){
        instIds += $(this).val()+","; 
    });
	var reportDate = $("#reportDate").val().split("-");
	var reprotDateBgn,reprotDateEnd;
	if(reportDate.length>0){
		if(reportDate[0]){
			reprotDateBgn = reportDate[0].trim().replace(/\//g,"-");;
		}
		if(reportDate[1]){
			reprotDateEnd = reportDate[1].trim().replace(/\//g,"-");;
		}
	}
	var resultData = judgeHasAttach(instIds,reprotDateBgn,reprotDateEnd);
	if(!resultData.success){
		ctools.alert("满足条件数据均未上传报告!","","warning");
		return;
	}
	window.location.href=encodeURI(TODO_PATH+"/batchEndFileDownload4Biz.do?bizType=INFO_DIS_REGULATORY&bizId=" + resultData.object);
}

/********************监管报告附件下载未与【我的】附件关系（已废弃）**********************/
//表单验证
function initValidate(){
	 $("#regulatoryReportForm").validate({
	        focusCleanup: true,
	        ignore : "",
	        rules: {
	        	prdCode:{
	            	required: true	
	            },
	            reportDate : {
	            	required: true
				},
	        },
	        messages: {
	        	prdCode : "请选择产品",
	        	reportDate : "请选择报告日期",
	        }
	    });
	 
}

function judgeHasAttachOld(instIds,reprotDateBgn,reprotDateEnd){
	var attachFlag = false;
	$.ajax({
		dataType: "json",
		type:'GET',
		url:encodeURI(REPORT_PATH_PREFIX+"/judgeHasAttach.do?sp[instIds]="+instIds+"&sp[reprotDateBgn]="+reprotDateBgn+"&sp[reprotDateEnd]="+reprotDateEnd+"&sp[flag]=R"+"&sp[batch]=true"),
		async:false,
		success: function(data){
			attachFlag = data;
		},
	});
	return attachFlag;
}

function downOld() {
	var instIds = "";
	$.each($("input[name='instId']:checked"),function(){
        instIds += $(this).val()+","; 
    });
	var reportDate = $("#reportDate").val().split("-");
	var reprotDateBgn,reprotDateEnd;
	if(reportDate.length>0){
		if(reportDate[0]){
			reprotDateBgn = reportDate[0].trim().replace(/\//g,"-");;
		}
		if(reportDate[1]){
			reprotDateEnd = reportDate[1].trim().replace(/\//g,"-");;
		}
	}
	var attachFlag = judgeHasAttach(instIds,reprotDateBgn,reprotDateEnd);
	if(attachFlag){
		ctools.alert("满足条件数据均未上传报告!","","warning");
		return;
	}
	window.location.href=encodeURI(REPORT_PATH_PREFIX+"/regulatoryReportDownNew.do?sp[instIds]="+instIds+"&sp[reprotDateBgn]="+reprotDateBgn+"&sp[reprotDateEnd]="+reprotDateEnd+"&sp[flag]=R"+"&sp[batch]=true");
}


